#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
import os

def computer_h(edge,label):
    gr = {}
    node = []

    with open(label,"r") as fp:
        nodes_label = fp.readlines()
        for node_label in nodes_label:
            node_label = node_label.split("\n")[0]
            node_label = node_label.split()
            cluster = node_label[1]
            nodename = node_label[2]
            gr[nodename] = cluster
    edge_list = []

    with open(edge,"r") as fp:
        edges = fp.readlines()
        for edge in edges:
            edge = edge.split("\n")[0]
            edge = edge.split()
            if len(edge) == 2:
                if edge[0][0] == '/':
                    edge[0]=edge[0][1:]

                if edge[1][0] == '/':
                    edge[1]=edge[1][1:]

                if [edge[0], edge[1]] not in edge_list:
                    edge_list.append([edge[0], edge[1]])
            else:
                if [edge[1],edge[2]] not in edge_list:
                    edge_list.append([edge[1],edge[2]])
    
    same = 0
    a=0
    b=0
    c=0
    d=0
    for edge in edge_list:
        if edge[0] not in node:
            node.append(edge[0])
        if edge[1] not in node:
            node.append(edge[1])

        if edge[0] not in gr and edge[1]not in gr:
            a+=1
            same+=1
        elif edge[0] not in gr or edge[1]not in gr:
            b+=1
            pass
        elif gr[edge[0]] == gr[edge[1]]:
            c+=1
            same+=1
        else:
            d+=1
    
    print(str(len(node)))
    print(str(len(edge_list)))
    #print(a)
    #print(b)
    print(c+a)#same
    print(d+b)#diff
    if d+b == 0:
        rate = "1:0"
    else: 
        rate = 1.0*(c+a)/(d+b)
    
    print(rate)
    #print("%.2f" % same/len(edge_list))

    return str(len(node)),str(len(edge_list)),str(a),str(b),str(d),str(c),str(same/len(edge_list))

if __name__ == '__main__':   
    sourcefile=sys.argv[1]#gt file
    targetfile=sys.argv[2]#our file

    
    if not os.path.exists(sourcefile):
        print('gt file is invalid')
        exit(1)
    if not os.path.exists(targetfile):
        print('your file is invalid')
        exit(1)
     #targetfile = '/home/jason/Documents/backup/documents/DAToolChain/function_sort.mdg'
     #sourcefile = '/home/jason/Documents/backup/documents/DAToolChain/outputexample/bash_gt.rsf'
    computer_h(targetfile,sourcefile)
